home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Frameworks / MacZoop 1.6.5 / More Classes / Advanced Dialogs / ZAdvancedDialog.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-27  |  7.3 KB  |  230 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************************
  2. *
  3. *
  4. *            ObjectMacZapp        -- a standard Mac OOP application template
  5. *
  6. *
  7. *
  8. *            ZAdvancedDialog.h    -- a dialog box that can be extended with new types of items.
  9. *                                    this will handle list boxes without subclassing.
  10. *
  11. *
  12. *            © 1997, Graham Cox
  13. *
  14. *
  15. *
  16. *************************************************************************************************/
  17.  
  18. #pragma once
  19.  
  20. #ifndef __ZADVANCEDDIALOG__
  21. #define    __ZADVANCEDDIALOG__
  22.  
  23.  
  24. #include    "ZDialog.h"
  25. #include    "ZObjectArray.h"
  26. #include    <Lists.h>
  27.  
  28. class    ZDialogItem;
  29.  
  30.  
  31. typedef    ZObjectArray<ZDialogItem>    ZDialogItemList;
  32.  
  33. typedef enum
  34. {
  35.     typeStaticText     = statText,
  36.     typeEditText     = editText,
  37.     typeIcon         = iconItem,
  38.     typePicture     = picItem,
  39.     typeButton         = btnCtrl,
  40.     typeCheckBox     = chkCtrl,
  41.     typeRadioButton = radCtrl,
  42.     typeResControl     = resCtrl,
  43.     typeUserItem    = 'user',
  44.     typeListBox     = 'list',
  45.     typeLine        = 'line',
  46.     type3DLine        = '3dln',
  47.     typeIconList    = 'icls'
  48. }
  49. ItemType;
  50.  
  51.  
  52. // generic item class:
  53.  
  54. class    ZDialogItem : public ZCommander
  55. {
  56. protected:
  57.     short        id;                // dialog item ID
  58.     ItemType    type;            // item type
  59.     Handle        iHand;            // original item handle
  60.     Rect        bounds;            // bounding box
  61.     Boolean        enabled;        // TRUE if item enabled for clicks
  62.     Boolean        canBeHandler;    // TRUE if this item can become part of the cmd chain
  63.     Boolean        isHandler;        // TRUE if currently is the handler for typing, etc.
  64.  
  65. public:    
  66.     ZDialogItem( ZDialog* aDialog, short item );
  67.     virtual ~ZDialogItem() {};
  68.     
  69.     virtual void        DrawItem() { FrameRect( &bounds ); };
  70.     virtual void        ClickItem( const Point where, const short modifiers ) {};
  71.     virtual void        AdjustCursor( const Point where, const short modifiers ) { SetCursor( &qd.arrow ); };
  72.     virtual void        InitItem( const long param1, const long param2 ) {};
  73.     virtual void        DrawBorder( Boolean bState );
  74.     virtual void        Activate( const Boolean isActive ) {};
  75.     virtual void        Idle() {};
  76.     
  77.     virtual void        SetCanBeHandler( Boolean hState ) { canBeHandler = hState; };
  78.     virtual void        BecomeHandler( Boolean isBecoming );
  79.     
  80.     inline    ItemType    GetType() { return type; };
  81.     inline    Boolean        ContainsPoint( Point where ) { return PtInRect( where, &bounds ); };
  82.     inline    short        GetID() { return id; };
  83.     inline    Boolean        Enabled() { return enabled; };
  84.     inline    Boolean        CanBeHandler() { return canBeHandler; };
  85. };
  86.  
  87. // messages sent by items when they change focus
  88.  
  89. enum
  90. {
  91.     ItemNowHandler         = 'ich+',
  92.     ItemNoLongerHandler = 'ich-'
  93. };
  94.  
  95. // lists can be constructed from resource templates. Here is the definition for
  96. // the template:
  97.  
  98. #if PRAGMA_ALIGN_SUPPORTED
  99. #pragma options align=mac68k
  100. #endif
  101.  
  102. typedef struct
  103. {
  104.     short        rows;                // number of rows
  105.     short        columns;            // number of columns
  106.     short        stringsListID;        // ID number of STR# resource to fill list with
  107.     short        procID;                // LDEF proc ID (0 for standard)
  108.     Boolean        hasVertScroll : 1;    // TRUE if has vertical scrollbar
  109.     Boolean        hasHorizScroll : 1;    // TRUE if has horizontal scrollbar
  110.     Boolean        hasGrowBox : 1;        // TRUE if has grow box
  111.     Boolean        visible : 1;        // TRUE if initially visible
  112.     Boolean        keyboardNav : 1;    // TRUE if can have the keyboard focus
  113.     long        refCon;                // reference constant
  114.     short        fontSize;            // size of font to use (uses window font if 0).
  115.     Str63        fontName;            // which font to use.
  116. }
  117. ListTemplate, *ListTemplatePtr, **ListTemplateHdl;
  118.  
  119.  
  120. #define        kListTemplateResType    'LIST'
  121.  
  122.     
  123. #if PRAGMA_ALIGN_SUPPORTED
  124. #pragma options align=reset
  125. #endif
  126.  
  127. // subclass of item to handle list box item
  128.  
  129. class    ZListDialogItem : public ZDialogItem
  130. {
  131. protected:
  132.     ListHandle        theList;        // the list manager list
  133.     Cell            lastSel;        // cell selected when deactivated
  134.     Str15            searchStr;        // for finding items in a list
  135.     long            lastKeyTime;    // time last key was typed
  136.     short            fThresh;        // reset threshold for typing
  137.     short            font;            // which font
  138.     short            fontSize;        // what size font
  139.     short            strListID;        // ID of string list to use
  140.  
  141. public:
  142.     ZListDialogItem( ZDialog* aDialog, const short item );
  143.     ~ZListDialogItem();
  144.  
  145.     virtual void        DrawItem();
  146.     virtual void        ClickItem( const Point where, const short modifiers );
  147.     virtual void        InitItem( const long param1, const long param2 );
  148.     virtual void        Type( const char theKey );
  149.     virtual void        BecomeHandler( Boolean isBecoming );
  150.     virtual void        Activate( const Boolean isActive );
  151.     virtual void        SetUpFontForList( short* curFont, short* curSize );
  152.     virtual void        UpdateMenus() {};
  153.     virtual void        AppendString( Str255 aString, Boolean drawIt = TRUE );
  154.  
  155.     inline    ListHandle    GetMacList() { return theList; };
  156.  
  157. protected:
  158.     virtual void        MakeMacList( const short listTemplateID = 0 );
  159.     virtual void        ActivateListItem( const Boolean state );
  160. };
  161.  
  162. // message sent from list box when a new item is selected
  163.  
  164. enum
  165. {
  166.     newListItemSelected = 'lstc',
  167.     listItemDoubleClicked = 'lsdb'
  168. };
  169.  
  170.  
  171. // advanced dialog class:
  172.  
  173. class    ZAdvancedDialog    : public ZDialog
  174. {
  175. protected:
  176.     ZDialogItemList*        itsItems;        // list of special object items
  177.     ZDialogItem*            curHandler;        // object that has keyboard focus
  178.     short                    focusItem;        // item ID that has focus, including real items
  179.  
  180. public:
  181.     ZAdvancedDialog( ZCommander* aBoss, const short dialogID );
  182.     ~ZAdvancedDialog();
  183.     
  184.     virtual    void            SetUp();
  185.     virtual void            ClickItem( const short item );
  186.     virtual void            DrawUserItem( const short item );
  187.     virtual Boolean            HasMultipleFoci();
  188.     virtual void            SelectItem( const short item );
  189.     virtual void            AdjustCursor( const Point mouse, const short modifiers );
  190.     virtual void            Deactivate();
  191.     virtual void            Activate();
  192.     virtual void            Type( const char theKey );
  193.     virtual ZDialogItem*    GetObjectItem( const short item );
  194.     virtual ZCommander*        GetHandler();
  195.  
  196. protected:
  197.     virtual void            ParseStatTextPseudoObjects( Str255 sText,
  198.                                                         long* typeParam,
  199.                                                         long* param1,
  200.                                                         long* param2 );
  201.     virtual void            BuildItemList();
  202.     
  203.     virtual ZDialogItem*    MakeObjectItem( const long aType, const short id );
  204.     virtual ZDialogItem*    FindObjectItem( const Point where );
  205.     virtual void            HiliteDialogText( Boolean state );
  206.     virtual Boolean            SelectNextFocus();
  207.     virtual void            ReceiveMessage( ZComrade* aSender, long aMessage, void* msgData );
  208. };
  209.  
  210.  
  211. extern UserItemUPP    gUIVectorUPP;
  212.  
  213. // this dialog class can do everything an ordinary dialog can, but in addition can display list-manager
  214. // lists. By default, the lists are set up with strings obtained from a STR# resource. This functionality
  215. // is based on an embryonic general dialog enhancement technique that will be further developed once we
  216. // know what sort of things are needed. In the meantime, this will handle list manager list boxes without
  217. // further subclassing.
  218.  
  219. // How this works is through the use of pseudo-items in the DITL template. These are declared as static
  220. // text items, but containing a special string sequence that this object parses and converts to other
  221. // object-based items. The strings must start with two dollar signs followed by the name of the object
  222. // then followed by a comma-delimited parameter list. e.g. "$$LIST,128,0". When this object encounters
  223. // this, it will a) convert the item to a user item and set up a drawing procedure for it via an object
  224. // of type ZDialogItem, b) extract the parameters and pass them to the item's initialiser, c) handle
  225. // clicks, etc in the item.
  226.  
  227. // Though apparently complex, this is a very powerful and easy to use feature once you get the hang of
  228. // it, requiring nothing more than setting up your DITL and making this object with it.
  229.  
  230. #endif